package com.srwl.mytx.activity;

import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Parcelable;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.util.Log;
import android.view.View;

import com.srwl.easeui.widget.MyTitleBar;
import com.srwl.mytx.Constant;
import com.srwl.mytx.R;
import com.srwl.mytx.adapter.MessageRecordAdapter;
import com.srwl.mytx.adapter.WrapContentLinearLayoutManager;
import com.srwl.mytx.domain.Message;
import com.srwl.mytx.domain.User;
import com.srwl.mytx.utils.MoonUtils;

import java.util.List;

/**
 * 本地搜索完成后，用于展示 多条匹配上的消息记录
 */
public class MessageRecordActivity extends BaseActivity {
    private static final String TAG = "MessageRecordActivity";
    private RecyclerView rv_messageRecord;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message_record);
        List<Message> messageList = getIntent().getParcelableArrayListExtra("messageList");
        User targetUser = getIntent().getParcelableExtra(Constant.EXTRA_TARGET_USER);
        if (messageList == null || messageList.size() == 0 || targetUser == null) {
            Log.e(TAG, "onCreate: 消息记录不能为空");
            return;
        }

        MyTitleBar titleBar = findViewById(R.id.title_bar);
        String title = targetUser.getUsername();
        SpannableString spannableString = MoonUtils.replaceEmoticonsAndHighlight(this, title, 0.6f, ImageSpan.ALIGN_BOTTOM, null,null);
        titleBar.setTitle(spannableString);
        rv_messageRecord = findViewById(R.id.rv_message_record);
        MessageRecordAdapter messageRecordAdapter = new MessageRecordAdapter(this, messageList);
        rv_messageRecord.setLayoutManager(new WrapContentLinearLayoutManager(this));
        rv_messageRecord.setAdapter(messageRecordAdapter);
    }

}
